package com.dongke.service.Impl;

import com.dongke.mapper.Car2Mapper;
import com.dongke.mapper.TcarMapper;
import com.dongke.pojo.Car2;
import com.dongke.pojo.Car2Example;
import com.dongke.pojo.Tcar;
import com.dongke.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private Car2Mapper car2Mapper;
    @Autowired
    private TcarMapper tcarMapper;
    @Override
    public PageInfo<Car2> selectgetCar(Car2 car2, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Car2> list = car2Mapper.selectInfo(car2);
        PageInfo<Car2> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer insertinto(Car2 car2) {
        int i = car2Mapper.insertSelective(car2);
        return i;
    }

    @Override
    public void delete(Integer[] arr) {
        car2Mapper.Deleteselected(arr);
    }

    @Override
    public Car2 selectCar(Integer cid) {
        Car2 car2 = car2Mapper.selectByPrimaryKey(cid);
        return car2;
    }

    @Override
    public void update(Car2 car2) {
        car2Mapper.updateByPrimaryKeySelective(car2);
    }

    @Override
    public void deletes(Integer cid) {
        car2Mapper.deleteByPrimaryKey(cid);
    }

    @Override
    public List<Tcar> selectCar2() {
        /*Car2Example car2Example = new Car2Example();
        Car2Example.Criteria criteria = car2Example.createCriteria();*/
        List<Tcar> car2s = tcarMapper.selectByExample(null);
        return car2s;
    }

    @Override
    public PageInfo getInfoServer(Car2 car2, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Car2> car2s = car2Mapper.getInfo(car2);
        PageInfo<Car2> car2PageInfo = new PageInfo<>(car2s);
        return car2PageInfo;
    }

    @Override
    public List<Car2> selectCar2s() {
        List<Car2> car2s = car2Mapper.selectByExample(null);
        return car2s;
    }

    @Override
    public int deleteBatch(Integer[] ids) {

        return car2Mapper.delteById(ids);
    }
}
